package com.wuxb.util.disruptor.main;

import com.lmax.disruptor.dsl.Disruptor;
import com.lmax.disruptor.dsl.EventHandlerGroup;
import com.wuxb.util.disruptor.DisruptorUtil;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;

public class Main extends DisruptorUtil {
    @Override
    public void doPattern(Disruptor disruptor) {
        //菱形操作
        //使用disruptor创建消费者组C1,C2
        EventHandlerGroup<Person> handlerGroup =
                disruptor.handleEventsWith(new PersonHandle1(),new PersonHandle2());
        //声明在C1,C2完事之后执行JMS消息发送操作 也就是流程走到C3
        handlerGroup.then(new PersonHandle3());
    }

    @Override
    public synchronized void doProduct(Disruptor disruptor,ExecutorService threadPool,CountDownLatch latch) {
        //生产者准备
        threadPool.submit(new TradePublisher(latch,disruptor));
    }



    public static void main(String[] args) {
        Main main = new Main();
        try {
            main.execute(Person.class);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
